<template>
  <van-icon color="#777" :name="value ? 'star' : 'star-o'" @click="onCollect"/>
</template>
<script>
import { addCollect, cancelCollect } from '@/api/article'
export default {
  name: 'CollectPage',
  components: {},
  props: {
    value: {
      type: Boolean,
      required: true,
    },
    articleId: {
      required: true
    }
  },
  data() {
    return {};
  },
  created() {},
  computed: {},
  methods: {
    onCollect() {
      if(this.value) {
        // 取消收藏
        cancelCollect(this.articleId).then(res => {
          console.log(res);
        }).catch(err => {
          console.log(err);
        })
      }else {
        // 收藏
        addCollect(this.articleId).then(res => {
          console.log(res);
        }).catch(err => {
          console.log(err);
        })
      }
      // 通知父组件视图更新 v-model默认事件名是input
      this.$emit('input', !this.value)
      this.$toast(!this.value ? '收藏成功' : '取消收藏')
    }
  },
};
</script>
<style lang='less' scoped>
.van-icon-star {
  color: #ffa500 !important;
}
</style>
